Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record search #5

Merged
merged 7 commits into from
Nov 9, 2020
Merged

Record search #5

merged 7 commits into from
Nov 9, 2020

Conversation

schneems
Copy link
Collaborator

@schneems schneems commented Nov 8, 2020

Many updates here, but the biggest win is that a search can now be recorded so after the fact an observer can replay the logic to look for bugs or optimizations.

When a block is added to the frontier, we remove it's lines from the indent_hash so that we do not accidentally re-create the same block multiple times. Previously this behavior was tied only to pushing a block to the frontier. 

This change exposes the behavior so that it can be invoked separately from pushing an object onto the frontier. Also when we generate a new block, we assume that it we don't want to re-generate the exact same block again (the method name is `next_block` after all) so we can go ahead and "register" it so we remove the appropriate lines from indent hash.

This also allows us to generate blocks and evaluate them without having to put them back into the frontier without needing to worry about generating the same block again.
- Allow toggling the terminal characters on/off
- Make indentation modular instead of being coupled to a specific method
- Rename "code with filename" to "code_block" since it no longer includes the filename
- Add a marker to invalid lines. Unicode arrow `❯` was chosen. It looks like this:

```
     1  module SyntaxErrorSearch
     2    # Used for formatting invalid blocks
     3    class DisplayInvalidBlocks
  ❯ 36      def filename
  ❯ 37
    38      def code_with_filename
    45      end
    46
    47      def code_with_lines
    62      end
    63    end
    64  end
```

- Method argument changed from positional to kwargs for the block array
While debugging a code search it's very useful to see not just what is returned, but also the process through which that result was created. This commit adds that functionality as well as a test. In the process of writing this code, the internals of the search were refactored a bit also I found a bug where I was accidentally calling `expand_until_neighbors` when I meant to call `expand_until_next_boundry`. This broke a bunch of very brittle test cases
@schneems schneems changed the title WIP Record search Nov 9, 2020
@schneems schneems merged commit eb0018f into main Nov 9, 2020
schneems added a commit that referenced this pull request Jan 15, 2022
# This is the 1st commit message:

Move queue logic and engulf logic to a class

The queuing and engulfing logic are tied together. We can bundle the two of them into a single class with a specific interface.
# This is the commit message #2:

WIP A*ish

# This is the commit message #3:

WIP with lex_diff OMG

# This is the commit message #4:

WIP Pull out "grab equal" logic of UpDownExpand

# This is the commit message #5:

WIP move class to proper file location

# This is the commit message #6:

WIP Fix spelling of method

# This is the commit message #7:

WIP LOL search

# This is the commit message #8:

Runs, finds the large code blocks, but is too greedy

# This is the commit message #9:

Move LexDiff to own class, refactor to an array

We're never using the hash keys so we don't need them. We can save memory and time by storing the values as an array.

# This is the commit message #10:

WIP LOL spec

# This is the commit message #11:

Micro optimize lex diff

# This is the commit message #12:

UpDownExpand fix major bug with internal mutability

When calling `line.lex_detect.dup` it was duplicating the outer memory, but not the inner memory. Internally we're using an array and the old array was still being referenced and mutated.

# This is the commit message #13:

LexDiff Huge perf upgrade

Store values in the object instead of an array.

# This is the commit message #14:

WIP playing with fuzzing this into the old algorithm

# This is the commit message #15:

WORKS and is hella fast

# This is the commit message #16:

WIP docs

# This is the commit message #17:

Put a max band on number of iterations

Unbounded while loops scare me, in theory this class should never iterate more than line times, but mistakes happen. When they do I want feedback for the user without disrupting the rest of their program.

# This is the commit message #18:

WIP Cleanup and docs

# This is the commit message #19:

WIP Cleanup and docs

# This is the commit message #20:

Standardrb

# This is the commit message #21:

Standardrb

# This is the commit message #22:

Refactor LexDiff, remove unused methods, add docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant